--[[
	获取七牛的上传token，secret_key放客户端不安全， 另外就是js这些加密算法方便写
]]
local filename = "getqiniutoken.lua"

local timetool = require "timetool"
local skynet = require "skynet"
local cluster = require "skynet.cluster"
local crypt = require "skynet.crypt"

local filelog =require "filelog"

local service = nil
local CMD = {
	service = nil
}

function CMD.process(rid, msgbody)
	if not service then
		service = CMD.service
	end 

	local uploadstr = msgbody.uploadstr or ''

	local encode_putpolicy = '{"scope":"'..uploadstr..'","deadline":'..(timetool.get_time()+259200000)..'}'
	encode_putpolicy = crypt.base64encode(encode_putpolicy)
	encode_putpolicy = string.gsub(encode_putpolicy, "+", "-")
	encode_putpolicy = string.gsub(encode_putpolicy, "/", "_")

	local sign = crypt.hmac_sha1(service.qiniu_secret_key, encode_putpolicy)
	local encode_sign = crypt.base64encode(sign)
	encode_sign = string.gsub(encode_sign, "+", "-")
	encode_sign = string.gsub(encode_sign, "/", "_")
	
	return {uploadtoken = service.qiniu_access_key ..":"..encode_sign..":"..encode_putpolicy}
end

return CMD